package com.chisheng.caa.util;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * SpringSecurity 工具类
 */
public final class SecurityUtil {

    private SecurityUtil() {
        throw new UnsupportedOperationException();
    }

    /**
     * 获取 SecurityContextHolder 中存储的用对象
     */
    @SuppressWarnings("unchecked")
    public static <T> T getPrincipal() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return (T) authentication.getPrincipal();
    }

}
